package com.jwell.docker.demo.controller;

import com.jwell.docker.demo.domain.Person;
import com.jwell.docker.demo.repository.PersonRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/")
@RestController
public class TestController {

    @Autowired
    private PersonRepository repository;

    @RequestMapping
    public String test() {
        return "test spring boot";
    }

    @RequestMapping("/id")
    public Person getPersonById(String id) {
        return repository.findOne(id);
    }

    @RequestMapping("/name")
    public Person getPersonByName(String name) {
        return repository.findByName(name);
    }

    @RequestMapping("/create")
    public boolean createPerson(@RequestParam String name, @RequestParam String id) {
        repository.save(new Person(id, name));
        return true;
    }
}
